<?php
require_once 'connection.php';

class User {
	public $userid=null;
	public $user=null;
	public $pass=null;
	public $email=null;
	public $admin=null;
	public $f_reg=null;
	public $avatar=null;
	
	public function loadUser ($email){
		global $connection;
		$data=array();
		if($data=$this->getUser($email)){
			$this->userid=$data[0];
			$this->user=$data[1];
			$this->pass=$data[2];
			$this->email=$data[3];
			$this->admin=$data[4];
			$this->f_reg=$data[5];
			$this->avatar=$data[6];
			return true;
		} else return false;
	}
	function getUser ($email) {
		global $connection;
		if($result=$connection->mysql->query("SELECT * FROM users WHERE email='".$email."'")){
			return $result->fetch_array(MYSQLI_BOTH);
		} else return false;
	}
	static function existUser ($user) {
		global $connection;
		$result=$connection->mysql->query("SELECT * FROM users WHERE user='".$user."'");
		if ($result->fetch_array(MYSQLI_BOTH)){
			return true;
		} else return false;
	}
	static function existEmail ($email) {
		global $connection;
		$result=$connection->mysql->query("SELECT * FROM users WHERE email='".$email."'");
		if ($result->fetch_array(MYSQLI_BOTH)){
			return true;
		} else return false;
	}
	static function isUser ($email, $password) {
		global $connection;
		$result=$connection->mysql->query("SELECT * FROM users WHERE email='".$email."' AND pass='".$password."'");
		if ($result->fetch_array(MYSQLI_BOTH)){
			return true;
		} else return false;
	}
	static function newUser ($user, $pass, $email) {
		global $connection;
		$query1=$connection->mysql->query("INSERT INTO users (user,pass,email,admin,f_reg) VALUES ('$user', '$pass', '$email', 'n', NOW())");
		if($query1) {
			return true;
		}else return false;
	}
}
?>